﻿using System.Data;
using System.Data.Odbc;
using System.Data.SqlClient;
using System.Data.OleDb;
//using System.Data.OracleClient;
using MySql.Data.MySqlClient;

namespace DataProvider
{
    public sealed class DBManagerFactory
    {
        private DBManagerFactory() { }
        public static IDbConnection GetConnection(DataProvider
         providerType)
        {
            IDbConnection iDbConnection = null;
            switch (providerType)
            {
                case DataProvider.SqlServer:
                    iDbConnection = new SqlConnection();
                    break;
                case DataProvider.OleDb:
                    iDbConnection = new OleDbConnection();
                    break;
                case DataProvider.Odbc:
                    iDbConnection = new OdbcConnection();
                    break;
                //case DataProvider.Oracle:
                //    iDbConnection = new OracleConnection();
                //    break;
                case DataProvider.MySql:
                    iDbConnection = new MySqlConnection();
                    break;
                default:
                    return null;
            }
            return iDbConnection;
        }

        public static IDbCommand GetCommand(DataProvider providerType)
        {
            switch (providerType)
            {
                case DataProvider.SqlServer:
                    return new SqlCommand();
                case DataProvider.OleDb:
                    return new OleDbCommand();
                case DataProvider.Odbc:
                    return new OdbcCommand();
                //case DataProvider.Oracle:
                //    return new OracleCommand();
                case DataProvider.MySql:
                    IDbCommand mysqlCommand = new MySqlCommand();
                    mysqlCommand.CommandTimeout = 0;
                    return mysqlCommand;
                default:
                    return null;
            }
        }

        public static IDbDataAdapter GetDataAdapter(DataProvider
        providerType)
        {
            switch (providerType)
            {
                case DataProvider.SqlServer:
                    return new SqlDataAdapter();
                case DataProvider.OleDb:
                    return new OleDbDataAdapter();
                case DataProvider.Odbc:
                    return new OdbcDataAdapter();
                //case DataProvider.Oracle:
                //    return new OracleDataAdapter();
                case DataProvider.MySql:
                    return new MySqlDataAdapter();
                default:
                    return null;
            }
        }        

        public static IDbDataParameter GetParameter(DataProvider providerType)
        {
            IDbDataParameter iDataParameter = null;
            switch (providerType)
            {
                case DataProvider.SqlServer:
                    iDataParameter = new SqlParameter();
                    break;
                case DataProvider.OleDb:
                    iDataParameter = new OleDbParameter();
                    break;
                case DataProvider.Odbc:
                    iDataParameter = new OdbcParameter();
                    break;
                //case DataProvider.Oracle:
                //    iDataParameter = new OracleParameter();
                //    break;
                case DataProvider.MySql:
                    iDataParameter = new MySqlParameter();
                    break;
            }
            return iDataParameter;
        }               
    }
}
